from tortoise import fields
from tortoise.models import Model

class SchedulesDB(Model):
    id = fields.IntField(pk=True, auto_generated=True)
    schedule_name = fields.TextField()
    start_time = fields.TextField()
    content=fields.TextField()
    status = fields.IntField(default=0)
    schedule_type = fields.IntField(default=1)
    created_at = fields.DatetimeField(auto_now_add=True)

    def to_dict(self):
        # Convert model instance to dictionary
        return {
            "id": self.id,
            "schedule_name": self.schedule_name,
            "start_time": self.start_time,
            "content": self.content,
            "status": self.status,
            "schedule_type": self.schedule_type,
            "created_at": self.created_at.strftime("%Y/%m/%d %H:%M:%S"),
        }

    class Meta:
        table = "schedules"